# -*- coding: utf-8 -*-
import re

def is_valid_email(addr):
    if re.match(r'^[a-zA-Z.]*@\w*.com$',addr):
        return True
    else: 
        return False
assert is_valid_email('someone@gmail.com')
assert is_valid_email('bill.gates@microsoft.com')
assert not is_valid_email('bob#example.com')
assert not is_valid_email('mr-bob@example.com')
print('ok')

reg=re.compile(r'\w{4}-12-31')
print(reg.match('1996-12-31'))
print(reg.match('2002-12-31'))
print(reg.match('1996-09-31'))

m = re.match(r'(\w+) (\w+)(?P<sign>.*)', 'hello world!')
print(m.string)
print(m.group(2))
print(m.groups())

p = re.compile(r'(\w+) (\w+)')
s = 'i say, hello world!'

print(p.sub(r'\2 \1', s))
print(p.sub('xx', s))


def func(m):
    return m.group(1).title() + ' ' + m.group(2).title()


print(p.sub(func, s))